package com.example;

import java.util.ArrayList;

import winterwell.jtwitter.Twitter.Status;
import android.content.Context;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class StatusAdapter extends ArrayAdapter<Status> {

	private ArrayList<Status> items;

	public StatusAdapter(Context context, int textViewResourceId,
			ArrayList<Status> items) {
		super(context, textViewResourceId, items);
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
					Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.row, null);
		}
		Status status = items.get(position);
		if (status != null) {
			TextView tvUser = (TextView) v.findViewById(R.id.textUser);
			TextView tvText = (TextView) v.findViewById(R.id.textText);
			TextView tvCreated = (TextView) v.findViewById(R.id.textCreatedAt);
			if (tvUser != null) {
				tvUser.setText(status.getUser().getName());
			}
			if (tvText != null) {
				tvText.setText(status.getText());
			}
			if (tvCreated != null) {
				tvCreated.setText(DateUtils.getRelativeTimeSpanString(status
						.getCreatedAt().getTime()));
			}
		}
		return v;
	}
}
